package threads;

public class UnSynchronizedBankTest {
	public static final int NUM_ACCOUNTS =100,
	DELAY=10;
	public static final double INIT_BALANCE=100,
	MAX_AMOUNT=1000;

	public static void main(String[] args) {
		var bank=new Bank(NUM_ACCOUNTS,INIT_BALANCE);
		for(int i = 0; i< NUM_ACCOUNTS; i++){
			int fromAccount=i;
			Runnable r=()->{
				try {
					while (true){
						int toAccount=(int)(bank.size()*Math.random());
						double amount=MAX_AMOUNT*Math.random();
						bank.transfer(fromAccount,toAccount,amount);
						Thread.sleep((int)(DELAY* Math.random()));

					}
				}catch (Exception ignored){}
			};
			new Thread((r)).start();
		}
	}
}
